package com.jinke.uang.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.jinke.uang.AppApplication;
import com.jinke.uang.constant.AuthTab;

import androidx.annotation.Nullable;

public class DbHelper extends SQLiteOpenHelper {
    private static DbHelper helper;
    public static int DB_VERSION = 2;

    public DbHelper(@Nullable Context context, @Nullable String name,
                    @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "CREATE TABLE " + AuthTab.TABLE_NAME + "(" + AuthTab.ID + " integer PRIMARY " +
                "KEY AUTOINCREMENT NOT NULL," + AuthTab.KEY + " varchar(20)," + AuthTab.VALUE +
                " varchar(36)," + AuthTab.STEP + " varchar(20)," + AuthTab.ISVALID + " integer)";
        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }


    public static synchronized DbHelper getInstance() {
        if (helper == null) {
            helper = new DbHelper(AppApplication.getContext(), "location.db", null, DB_VERSION);
        }
        return helper;
    }
}
